import axios from "@/util/http";

export default {
  state: {
    uid: "",
    id: "",
    name: "",
    sex: "",
    phone: "",
  },
  getters: {},
  mutations: {
    setManagerUid(state, uid) {
      state.uid = uid;
    },
    setManagerState(state, data) {
      state.id = data.id;
      state.name = data.name;
      state.sex = data.sex;
      state.phone = data.phone;
    },
  },
  actions: {
    get_manager_info(context, data) {
      const url = "/manager/get/manager/info/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        context.commit("setManagerState", resp.data.data);
        context.commit("setManagerUid", data.uid);
      });
    },
    modify_manager_info(context, data) {
      const url = "/manager/modify/";
      const postData = data.data;
      const config = {
        headers: {
          Authorization: "Bearer " + postData.token,
        },
      };
      postData.token = null;
      axios
        .post(url, postData, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          data.error(resp.data);
        });
    },
  },
  modules: {},
};
